<?php namespace Home\Controller; 
use Hdphp\Controller\Controller;

//测试控制器
class IndexController extends Controller{

    //动作
    public function index(){
    	$data=Db::table('Category')->where()->get();
		$datal=Db::table('Category')->where("pid=0")->get();
		$datat=Db::table('Category')->where("pid=0")->orderBy('csort','DESC')->limit(8)->get();
		foreach ($datal as $k => $v) {
			$cdata[$v['cid']]=$this->getSon($data,$v['cid']);
		}
		View::with('cdata',$cdata);
		View::with('datat',$datat);
       View::make();
    }
	public function getSon($data,$cid)
	{
		static $temp=array();
		foreach ($data as $v) {
			if($cid==$v['pid']){
				$temp[]=$v['cid'];
				$this->getSon($data,$v['cid']);
			}
		}
		$cids=implode(',',$temp);
		$datan=Db::table('Category')->where("cid in ({$cids}) and pid={$cid}")->get();
		return $datan;
	}
}
